package com.ruoyi.web.controller.billSettings;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EmployeeSchedule;
import com.ruoyi.system.service.IEmployeeScheduleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工排班Controller
 *
 * @author ruoyi
 * @date 2025-05-12
 */

@Api(tags="员工排班")
@RestController
@RequestMapping("/system/employeeSchedule")
public class EmployeeScheduleController extends BaseController
{
    @Autowired
    private IEmployeeScheduleService employeeScheduleService;

    /**
     * 通过班组名称查询员工排班列表
     */
    @ApiOperation("通过班组名称查询员工排班列表")
    @PreAuthorize("@ss.hasPermi('system:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String teamName)
    {
        startPage();
        List<EmployeeSchedule> list = employeeScheduleService.selectEmployeeScheduleListByName(teamName);
        return getDataTable(list);
    }

    /**
     * 导出员工排班列表
     */
    @ApiOperation("导出员工排班列表")
    @PreAuthorize("@ss.hasPermi('system:schedule:export')")
    @Log(title = "员工排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String teamName)
    {
        List<EmployeeSchedule> list = employeeScheduleService.selectEmployeeScheduleListByName(teamName);
        ExcelUtil<EmployeeSchedule> util = new ExcelUtil<EmployeeSchedule>(EmployeeSchedule.class);
        util.exportExcel(response, list, "员工排班数据");
    }

    /**
     * 通过id获取员工排班详细信息
     */
    @ApiOperation("通过id获取员工排班详细信息")
    @PreAuthorize("@ss.hasPermi('system:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(employeeScheduleService.selectEmployeeScheduleById(id));
    }

    /**
     * 新增员工排班
     */
    @ApiOperation("新增员工排班")
    @PreAuthorize("@ss.hasPermi('system:schedule:add')")
    @Log(title = "员工排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmployeeSchedule employeeSchedule)
    {
        return toAjax(employeeScheduleService.insertEmployeeSchedule(employeeSchedule));
    }

    /**
     * 修改员工排班
     */
    @ApiOperation("修改员工排班")
    @PreAuthorize("@ss.hasPermi('system:schedule:edit')")
    @Log(title = "员工排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmployeeSchedule employeeSchedule)
    {
        return toAjax(employeeScheduleService.updateEmployeeSchedule(employeeSchedule));
    }

    /**
     * 通过id批量删除员工排班
     */
    @ApiOperation("通过id批量删除员工排班")
    @PreAuthorize("@ss.hasPermi('system:schedule:remove')")
    @Log(title = "员工排班", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(employeeScheduleService.deleteEmployeeScheduleByIds(ids));
    }
}
